package database;

import java.sql.CallableStatement;

import object.RMP;
import clientMain.Login;

public class RMPDelegate {

	public boolean insertRoleModule(RMP ro, int userInsert, String listModule){
		boolean flag = true;
		try {
			Login.conn.setAutoCommit(false);
			CallableStatement cst = Login.conn.prepareCall("{call sp_InsertRole_Module(?,?,?,?)}");
			cst.setInt(1, ro.getRoleId());
			cst.setInt(2, userInsert);
			cst.setString(4,listModule);
			cst.executeUpdate();
			Login.conn.commit();
		} catch (Exception e) {
			flag = false;
		}
		return flag;
	}	
	
	public boolean updateRoleModule(RMP ro, int userUpdate, String listModule){
		boolean flag = true;
		try {
			Login.conn.setAutoCommit(false);
			CallableStatement cst = Login.conn.prepareCall("{call sp_UpdateRole_Module(?,?,?)}");
			cst.setInt(1, ro.getRoleId());
			cst.setString(2,listModule);
			cst.setInt(3, userUpdate);
			cst.executeUpdate();
			Login.conn.commit();
		} catch (Exception e) {
			e.printStackTrace();
			flag = false;
		}
		return flag;
	}
}
